#ifndef YCBASECOPYFILE_H
#define YCBASECOPYFILE_H
#include <QObject>

namespace yc {

// 复制文件到指定的目录，如果未指定新的文件名，会以文件内容的MD5命名文件
class CopyFilePrivate;
class CopyFile : public QObject
{
    Q_OBJECT

public:
    explicit CopyFile(QObject* parent = nullptr);
    ~CopyFile();

    void copy(const QString& file_name, const QString& target_dir, const QString& new_file_name);

Q_SIGNALS:
    void operate(const QString& file_name, const QString& target_dir, const QString& new_file_name);
    void finished(const QString& file_name, const QString& id);

private:
    CopyFilePrivate* ptr_;
};

class CopyFileWorker : public QObject
{
    Q_OBJECT

public:
    explicit CopyFileWorker(QObject* parent = nullptr);

    static QString calcFileID(const QString& file_name, bool multi_times);
    static bool copy(const QString& file_name, const QString& new_file_name, bool multi_times);
    static QString copyTo(const QString& file_name, const QString& target_dir,
                          const QString& new_file_name);

    static qint64 calcFileIDCost(qint64 size);
    static qint64 copyFileCost(qint64 size);

public Q_SLOTS:
    void doWork(const QString& file_name, const QString& target_dir, const QString& new_file_name);

Q_SIGNALS:
    void finished(const QString& file_name, const QString& id);

private:
    static volatile qint64 calc_id_speed;
    static volatile qint64 copy_speed;
};
} // namespace yc

#endif // YCBASECOPYFILE_H
